<template>
	<view class="wrap">
		<u-top-tips ref="uTips"></u-top-tips>
		<view class="cu-bar bg-white ">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<u-input @confirm="search" :focus="firstFocus"  v-model="cbarCode" type="text" placeholder="请扫描识别码"></u-input>
			</view>
			<view class="action" @click="toScan">
				<text class="cuIcon-scan" style="font-size: 56rpx;"></text>
			</view>
		</view>
		<u-form class="form" :model="model" ref="uForm" label-position="left" v-if="show">
			<u-form-item label="存货名称:" prop="invName" label-width="140" >
				<u-input v-model="model.invName" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="存货编码:" prop="invCode" label-width="140" >
				<u-input v-model="model.invCode" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="规格型号:" prop="invStd" label-width="140" >
				<u-input v-model="model.invStd" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="箱码:" prop="boxCode" label-width="140" >
				<u-input v-model="model.boxCode" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="产品码:" prop="procode" label-width="140" v-if="model.comounit == '罐'">
				<u-input v-model="model.procode" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="发货单号:" prop="fhCode" label-width="140" >
				<u-input v-model="model.fhCode" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="出库单号:" prop="ckCode" label-width="140" >
				<u-input v-model="model.ckCode" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="市代名称:" prop="sdName" label-width="140" >
				<u-input v-model="model.sdName" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="门店名称:" prop="mdName" label-width="140" >
				<u-input v-model="model.mdName" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="发货时间:" prop="fhDate" label-width="140" >
				<u-input v-model="model.fhDate" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="生产日期:" prop="scDate" label-width="140" >
				<u-input v-model="model.scDate" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="批次:" prop="beach" label-width="140" >
				<u-input v-model="model.beach" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="单位:" prop="boxType" label-width="140" >
				<!-- <u-input v-model="model.boxType" :disabled="true" placeholder='' type="text" di maxlength="64" ></u-input> -->
				<js-select v-model="model.boxType" dict-type="btdm_bar_type" placeholder='' :disabled="true"></js-select>
			</u-form-item>
			<u-form-item label="物流单号:" prop="wlCode" label-width="140" >
				<u-input v-model="model.wlCode" placeholder='' :disabled="true" type="text" di maxlength="64"></u-input>
			</u-form-item>
			
			<!-- <u-form-item label="箱码:" prop="boxCode" label-width="140" >
				<u-input v-model="model.boxCode" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="产品码:" prop="procode" label-width="140" v-if="model.comounit == '罐'">
				<u-input v-model="model.procode" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="存货名称:" prop="cinvname" label-width="140" >
				<u-input v-model="model.cinvname" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="生产日期:" prop="scDate" label-width="140" >
				<u-input v-model="model.scDate" :disabled="true" type="date"  placeholder='' di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="批次:" prop="bachNum" label-width="140" >
				<u-input v-model="model.bachNum" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="单位:" prop="code" label-width="140" >
				<u-input v-model="model.comounit" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="出库单号:" prop="cCode" label-width="140" >
				<u-input v-model="model.cCode" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="客户名称:" prop="cCusName" label-width="140" >
				<u-input v-model="model.cCusName" :disabled="true" placeholder='' type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="物流公司:" prop="cExpressCoName" label-width="140" >
				<u-input v-model="model.cExpressCoName" placeholder='' :disabled="true" type="text" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="物流单号:" prop="cEBExpressCode" label-width="140" >
				<u-input v-model="model.cEBExpressCode" placeholder='' :disabled="true" type="text" di maxlength="64"></u-input>
			</u-form-item> -->
		</u-form>
		<js-error mode="bottom" ref="jsError"></js-error>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				numList: [{
						name: '扫描箱码'
					}, {
						name: '确认数据'
					}, 
				],
				size:-1,
				show:false,
				cbarCode:'',
				model:{
					boxCode:'',
					procode:'',
					cinvname:'',
					bachNum:'',
					comounit:'',
					cCode:'',
					cDLCode:'',
					cCusName:'',
					scDate:'',
					cEBExpressCode:'',
					cExpressCoName:'',
				},
				firstFocus: true,
			}
		},
		onLoad() {
			var _this = this;
			setTimeout(() => {
				this.firstFocus = true
			},0)
		},
		methods: {
			/** 扫码查询*/
			search(){
				this.firstFocus = false
				var code = this.cbarCode;
				if(code == undefined || code == ''){
					//闪现提示
					this.$u.toast('您扫描的条码有误,请重新扫码。');
					//确认提示
				}else{
					if(code.indexOf("http://") > -1 || code.indexOf("https://") > -1){
						code = code.split("=")[1];
						this.loadData(code);
					}else{
						this.loadData(code);
					}
				}
			},
			/** 扫码 */
			toScan() {
				// #ifdef APP-PLUS
				var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
				mpaasScanModule.mpaasScan({
					// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
					'scanType': ['qrCode', 'barCode'],
					// 是否隐藏相册，默认false不隐藏
					'hideAlbum': false,
					//ios需要设置这个参数，只支持中英文 zh-Hans、en，默认中文                       
					'language': 'en',
					//相册选择照片识别错误提示(ios)
					'failedMsg': '未识别到二维码，请重试',
					//Android支持全屏需要设置此参数
					'screenType': 'full'
				},
					async (ret) => {
						console.log('ret', ret)
						if (ret.resp_message == 'success') {							
							var code = ret.resp_result;
							if(code.indexOf("http://") > -1  || code.indexOf("https://") > -1){
								code = code.split("=")[1];
								await this.loadData(code);
							}else{
								await this.loadData(code);
							}
						}
					})
				// #endif
				// #ifdef H5 || MP-WEIXIN || MP-QQ 
				uni.scanCode({ 
					onlyFromCamera: true,
					success: async function(res) {
						var code = res.result;
						if(code.indexOf("http://") > -1  || code.indexOf("https://") > -1){
							code = code.split("=")[1];
							await this.loadData(code);
						}else{
							await this.loadData(code);
						}
					}.bind(this)
				});
				// #endif
			},
			/** 数据加载 */
			async loadData(code){
				//105343222202010000057143
				// var code = '00202204500929799129'
				if(code != undefined && code != ''){
					var query = {
						"barcode":code
					}
					await  this.$u.api.zgz.getReviewInfo(query).then(res=>{
						this.cbarCode = "";
						if(res.result != 'true'){
							this.$u.toast('您扫描的条码有误,请重新扫码。');
							return;
						}
						if(res.data.boxCode ==undefined || res.data.boxCode == ''){
							this.$u.toast('您扫描的条码有误,请重新扫码。');
							return;
						}
						this.model = {
							...res.data
						}
						// this.model.boxCode = res.data.boxCode;
						// this.model.procode = res.data.procode;
						// this.model.cinvname = res.data.cinvname;
						// this.model.bachNum = res.data.bachNum;
						// this.model.cCode = res.cCode;
						// this.model.cDLCode = res.cDLCode;
						// this.model.cCusName = res.cCusName;
						// this.model.scDate = res.scDate;
						// this.model.cEBExpressCode = res.cEBExpressCode;
						// this.model.cExpressCoName = res.cExpressCoName;
						if(this.model.procode !=undefined && this.model.procode != ''){
							this.model.comounit = '罐'
						}else{
							this.model.comounit = '箱'
						}
					})
				}
				this.show = true
				this.cbarCode = ''
			},
		}
	}
</script>

<style>
@import '../btdm.css';
</style>
<style scoped lang="scss">
	.u-form-item{
		font-size: 30rpx !important;
	}
</style>
